import 'package:flutter/cupertino.dart';
import 'package:jump_scape/js_config.dart';
import 'package:jump_scape/js_data/js_http/js_http.dart';

import 'js_box/js_init.dart';

class JsCommon {
  void getAppConfig() async {
    final ver = (await JsObjectBox.setting).appConfigVer;
    final body = await JsHttp.get(JsApp.jsHttpAppConfig, {"ver": ver});
    bool isSucc = body[1];
    if (isSucc) {
      Map<String, dynamic> map = body[2];

      final setting = await JsObjectBox.setting;

      setting.appConfigVer = map["ver"].toString();
      
      List<dynamic> items = map["items"];
      for (Map<String, dynamic> item in items) {
        if ("google_translation_key" == item["name"]) {
          setting.googleTranslationKey = item["data"];
        }
      }

      JsObjectBox.settingBox.put(setting);

      debugPrint("[setting] ✅ $setting");
    }
  }
}
